<!--
 * @Description:
 * @Author: oscar
 * @Date: 2021-12-14 14:53:14
-->
<template>
  <h3>企业数据列表</h3>

  <SearchForm :searchColumns="searchColumns" @searchSubmit="searchEvent"></SearchForm>

  <Table
  :loading="loading"
  :tableData="tableData"
  :tableColumns="tableColumns"
  :options="tableOptions"
  :total="total"
  :pages="pages"
  @pageEvent="handleCurrentChange">
    <template v-slot:op="scope">
      <el-button type="text" @click="getLogin(scope)">获取登录地址</el-button>
    </template>
  </Table>

  <el-dialog v-model="dialogTableVisible" title="登录地址">
    <div class="links">
      <p>
        <el-tag>管理员身份:</el-tag>
      </p>
      <p>{{link +'1'}}</p>
      <p>
        <el-tag>导购身份:</el-tag>
      </p>
      <p>{{link +'0'}}</p>
    </div>
  </el-dialog>

</template>

<script lang="ts">
  import { getCompanyList } from '@/api/company'
  import { searchColumns, tableColumns, tableOptions } from './config/companyTable'
  import SearchForm from '@/components/search/index.vue'
  import Table from '@/components/table/index.vue'
  import { reactive } from "vue"

  export default {
    name: "company",
    components: {
      SearchForm,
      Table
    },
    data() {
      return {
        loading: false,
        dialogTableVisible: false, // 地址显示框
        tableData: [],
        total: 0,
        pages: {
          p: 1,
          limit: 10
        }
      }
    },
    setup() {


      return {
        searchColumns,
        tableColumns,
        tableOptions
      }
    },
    created() {
      this.getList();
    },
    methods: {
      // 获取列表数据
      getList(search) {
        this.loading = true
        const pages = {
          ...this.pages
        }
        let params = {}
        if(search) {
          params = Object.assign(pages, search)
        } else {
          params = pages
        }
        getCompanyList(params).then((res) => {
          this.tableData = res.list
          this.total = res.total
          this.loading = false
        });
      },

      // 点击跳转到指定页
      handleCurrentChange(val) {
        this.pages.p = val
        this.getList()
      },

      // 搜索
      searchEvent(data) {
        const search = JSON.parse(JSON.stringify(data))
        let params = {}
        if (search) {
          for (let key in search) {
            if (String(search[key]).length > 0) {
              params[key] = search[key]
            }
          }
        }
        this.pages.p = 1
        this.getList(params)
      },

      // 获取登录地址
      getLogin(data) {
        const row = data.scope.row
        const param = {
          qid: row.qid,
          did: row.did,
          id: row.id,
          userid: row.userid
        }
        // getSalesmanLoginUrl(param).then(res => {
        //   this.link = res
        //   this.dialogTableVisible = true
        // })
      }
    },
  };
</script>